from client.errors import NDFSError

class KuaiPanError202(NDFSError):  
    default_message = "KuaiPan Run Error"

class KuaiPanError400(NDFSError):  
    default_message = "KuaiPan Parameter Error"

class KuaiPanError401(NDFSError):  
    default_message = "KuaiPan Authorization Error"

class KuaiPanError403(NDFSError):  
    default_message = "KuaiPan No Permission"

class KuaiPanError404(NDFSError):  
    default_message = "KuaiPan Not Exist"
    
class KuaiPanError405(NDFSError):  
    default_message = "KuaiPan Path Wrong"

class KuaiPanError406(NDFSError):  
    default_message = "KuaiPan Too Many Files"

class KuaiPanError413(NDFSError):  
    default_message = "KuaiPan Too Large File"

class KuaiPanError500(NDFSError):  
    default_message = "KuaiPan Server Internal Error"

class KuaiPanError507(NDFSError):  
    default_message = "KuaiPan Space Not Enough"
    
class KuaiPanError5xx(NDFSError):  
    default_message = "KuaiPan Server Error, Out of Service"
    
def check_status(status, data=None):
    if 200 == status:
        return
    elif 202 == status:
        raise KuaiPanError202, KuaiPanError202.default_message, data
    elif 400 == status:
        raise KuaiPanError400
    elif 401 == status:
        raise KuaiPanError401, '%s:%s' % (KuaiPanError401.default_message, data)
    elif 403 == status:
        raise KuaiPanError403
    elif 404 == status:
        raise KuaiPanError404
    elif 405 == status:
        raise KuaiPanError405
    elif 406 == status:
        raise KuaiPanError406
    elif 413 == status:
        raise KuaiPanError413
    elif 500 == status:
        raise KuaiPanError500
    elif 507 == status:
        raise KuaiPanError507
    elif 500 < status and status < 600:
        raise KuaiPanError5xx
    else:
        raise NDFSError, 'KuaiPan Unkown Error:%s' % data

